package com.eclink.iot.tcp.virtualdevice;

import com.eclink.iot.tcp.virtualdevice.entity.Device;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

public class VirtualDeviceManager {

    @Getter
    private static final List<VirtualDevice> devices = new ArrayList<>();

    /**
     * 创建
     * @return 实体
     */
    public static VirtualDevice publicDevice(Device device) {
        VirtualDevice proxy = new VirtualDevice(device);
        devices.add(proxy);
        return proxy;
    }

    private VirtualDevice getVirtualDeviceByUUID(String uuid) {
        for(VirtualDevice device : devices) {
            if(device.getUuid().equals(uuid)) {
                return device;
            }
        }
        return null;
    }

    /**
     * 指定的虚拟设备发送标签
     * @param uuid UUID
     * @param tag 标签
     * @return 虚拟设备
     */
    public VirtualDevice sendTag(String uuid, String tag) {
        VirtualDevice virtualDevice = getVirtualDeviceByUUID(uuid);
        if(virtualDevice == null) {
            return null;
        }
        virtualDevice.sendTag(tag);
        return virtualDevice;
    }

}
